package com.sky.controller.user;

import com.sky.dto.OrdersPageQueryDTO;
import com.sky.pojo.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.user.HistoryOrdersService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user/order")
@Slf4j
@Api(tags = "历史订单接口")
public class HistoryOrdersController {
    @Autowired
    private HistoryOrdersService historyOrdersService;

    @GetMapping("/historyOrders")
    @ApiOperation("查询所有历史订单")
    public Result<PageResult> getHistoryOrders(OrdersPageQueryDTO ordersdTO){
        return  historyOrdersService.selectHistoryOrdersList(ordersdTO);
    }
    @GetMapping("/queryOrdersCheckStatus")
    @ApiOperation("查询待确认的订单")
    public Result<PageResult> getCanCancelOrder(OrdersPageQueryDTO ordersdTO){
        return  historyOrdersService.selectCanCancelOrdeList(ordersdTO);
    }

    @GetMapping("/orderDetail/{orderId}")
    @ApiOperation("查询订单详情")
    public Result<Orders> getOrdersInfor(@PathVariable Long orderId){
        return historyOrdersService.getOrdersInfor(orderId);
    }

    @PostMapping("/cancel/{id}")
    @ApiOperation("取消订单")
    public Result<String> cancelOrder(@PathVariable Long id){
        return historyOrdersService.cancleOrder(id);

    }
    @PostMapping("/repetition/{id}")
    @ApiOperation("再来一单")
    public Result<String> OrderAgain(@PathVariable Long id){
       historyOrdersService.orderAgain(id);
        return Result.success();
    }

}
